/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JCheckBox;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.plaf.SliderUI;

/**
 *
 * @author cespitia
 */
public class FrameManager extends Frame {

    private int alto, ancho, x, y, xElement, yElement, ancElement, altElement;
    private Color fondo, texto;
    private String name;

    public FrameManager(String name) {
        this.name = name;
        this.setName(this.name);
        this.setTitle(this.name);
        this.alto = 0;
        this.ancho = 0;
        this.x = 0;
        this.y = 0;
        this.fondo = Color.white;
        this.texto = Color.black;
        this.xElement = 0;
        this.yElement = 0;
        this.altElement = 10;
        this.ancElement = 10;
    }

    public String ajustarTamanioAlto(int alto) {
        this.alto = alto;
        this.setBounds(this.x, this.y, this.ancho, this.alto);
        return "\n\t\t//Le damos tamaño a la ventana pero solo el alto\n\t\tfr.setBounds(" + this.x + ", " + this.y + ", " + this.ancho + ", " + this.alto + ");\n";
    }
    public String ajustarTamanioAncho( int ancho) {
        this.ancho = ancho;
        this.setBounds(this.x, this.y, this.ancho, this.alto);
        return "\n\t\t//Le damos tamaño a la ventana del ancho\n\t\tfr.setBounds(" + this.x + ", " + this.y + ", " + this.ancho + ", " + this.alto + ");\n";
    }

    public void ajustarPosicion(int x, int y) {
        this.x = x;
        this.y = y;
        this.setBounds(this.x, this.y, this.alto, this.ancho);
    }

    public String ajustarColor(String fondo, String texto) {
        this.fondo = this.seleccionaColor(fondo);
        this.texto = this.seleccionaColor(texto);
        this.setBackground(this.fondo);
        this.setForeground(this.texto);
        Color c = this.texto;
        return "\n\t\t//Asignamos el color de fondo\n\t\tfr.setBackground(Color." + fondo + ");\n\t\t//Asignamos el color de la fuente\n\t\tfr.setForeground(Color." + texto + ");\n";
    }

    public String permitirReajuste(boolean check) {
        this.setResizable(check);
        return "\n\t\t//lo hacemos de tamaño ajustable\n\t\tfr.setResizable(" + check + ");\n";
    }

    public String agregarElemento(int elemtent, String name, int alto, int ancho, String valor) {
        switch (elemtent) {
            case 0:
                Label label = new Label(valor);
                label.setName(name);
                label.setBounds(this.xElement, this.yElement, ancho, alto);
                this.add(label);
                return "\n\n\t\tLabel " + name + " = new Label(\"" + valor + "\");\n"
                        + "\t\t" + name + ".setBounds(" + this.xElement + ", " + this.yElement + ", " + ancho + ", " + alto + ");\n"
                        + "\t\tthis.add(" + name + ");\n";
            case 1:
                Button but = new Button(valor);
                but.setName(name);
                but.setBounds(this.xElement, this.yElement, this.ancElement, this.altElement);
                this.add(but);
                return "\n\n\t\tButton " + name + " = new Button(\"" + valor + "\");\n"
                        + "\t\t" + name + ".setBounds(" + this.xElement + ", " + this.yElement + ", " + ancho + ", " + this.altElement + ");\n"
                        + "\t\tthis.add(" + name + ");\n";
            case 2:
                TextField txf = new TextField(valor);
                txf.setName(name);
                txf.setBounds(this.xElement, this.yElement, ancho, alto);
                this.add(txf);
                return "\n\n\t\tTextField " + name + " = new TextField(\"" + valor + "\");\n"
                        + "\t\t" + name + ".setBounds(" + this.xElement + ", " + this.yElement + ", " + ancho + ", " + alto + ");\n"
                        + "\t\tthis.add(" + name + ");\n";
            case 3:
                TextArea txa = new TextArea(valor);
                txa.setName(name);
                txa.setBounds(this.xElement, this.yElement, this.ancElement, this.altElement);
                txa.setRows(ancho / 2);
                txa.setColumns(alto / 2);
                this.add(txa);
                return "\n\n\t\tTextArea " + name + " = new TextArea(\"" + valor + "\");\n"
                        + "\t\t" + name + ".setBounds(" + this.xElement + ", " + this.yElement + ", " + this.ancElement + ancho + ", " + this.altElement + ");\n"
                        + "\t\tthis.add(" + name + ");\n";
            case 4:
                Choice chc = new Choice();
                chc.setName(name);
                chc.setBounds(this.xElement, this.yElement, this.ancElement, this.altElement);
                chc.addItem(valor+" 1");
                chc.addItem(valor+" 2");
                chc.addItem(valor+" 3");
                chc.addItem(valor+" 4");
                this.add(chc);
                return "\n\n\t\tChoice " + name + " = new Choice();\n"
                        + "\t\t" + name + ".setBounds(" + this.xElement + ", " + this.yElement + ", " + this.ancElement + ancho + ", " + this.altElement + ");\n"
                        + "\n\t\t" + name + ".addItem(\""+valor+" 1\" );"
                        + "\n\t\t" + name + ".addItem(\""+valor+" 2\" );"
                        + "\n\t\t" + name + ".addItem(\""+valor+" 3\" );"
                        + "\n\t\t" + name + ".addItem(\""+valor+" 4\" )\n;"
                        + "\t\tthis.add(" + name + ");\n";
            case 5:
                JRadioButton jrb = new JRadioButton();
                jrb.setName(name);
                jrb.setText(valor);
                jrb.setBounds(this.xElement, this.yElement, this.ancElement, this.altElement);
                this.add(jrb);
                return "\n\n\t\tJRadioButton " + name + " = new JRadioButton();\n"
                        + "\t\t" + name + ".setBounds(" + this.xElement + ", " + this.yElement + ", " + this.ancElement + ancho + ", " + this.altElement + ");\n"
                        + "\n\t\t" + name + ".setText(\""+valor+" \" );"
                        + "\t\tthis.add(" + name + ");\n";
            case 6:
                JCheckBox jcb = new JCheckBox();
                jcb.setName(name);
                jcb.setText(valor);
                jcb.setBounds(this.xElement, this.yElement, this.ancElement, this.altElement);
                this.add(jcb);
                return "\n\n\t\tJCheckBox " + name + " = new JCheckBox();\n"
                        + "\t\t" + name + ".setBounds(" + this.xElement + ", " + this.yElement + ", " + this.ancElement + ancho + ", " + this.altElement + ");\n"
                        + "\n\t\t" + name + ".setText(\""+valor+" \" );"
                        + "\t\tthis.add(" + name + ");\n";
            case 7:
                JPasswordField pwf = new JPasswordField(valor);
                pwf.setName(name);
                pwf.setText("valor");
                pwf.setBounds(this.xElement, this.yElement, ancho, alto);
                this.add(pwf);
                return "\n\n\t\tTextField " + name + " = new TextField(\"" + valor + "\");\n"
                        + "\t\t" + name + ".setBounds(" + this.xElement + ", " + this.yElement + ", " + ancho + ", " + alto + ");\n"
                        + "\t\tthis.add(" + name + ");\n";
        }
        return null;
    }

    public String permitirCerrar(boolean dato) {
        if (dato) {
            this.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosing(WindowEvent we) {
                    setVisible(false);
                }
            });
            return "\n\t\t//Agregamos un WindowListener que permite cerrar la ventana\n\t\tfr.addWindowListener(new WindowAdapter() {\n\t\t\t@Override\n\t\t\tpublic void windowClosing(WindowEvent we) {\n\t\t\t\tsetVisible(false);\n\t\t\t}\n\t\t});\n";
        }
        return "\n";
    }

    public String permitirMaxMin(int estado) {
        switch (estado) {
            case 1:
                this.setExtendedState(Frame.MAXIMIZED_BOTH);
                return "\n\t\t//Asignamos el estado de la ventana a maximizado\n\t\tfr.setExtendedState(Frame.MAXIMIZED_BOTH);\n";
            case 2:
                this.setExtendedState(Frame.ICONIFIED);
                return "\n\t\t//Asignamos el estado de la ventana a minimizado\n\t\tfr.setExtendedState(Frame.ICONIFIED);\n";
        }
        return "\n";
    }

    private Color seleccionaColor(String color) {
        /**/
        if (color.equals("RED")) {
            return Color.RED;
        } else if (color.equals("GREEN")) {
            return Color.GREEN;
        } else if (color.equals("BLUE")) {
            return Color.BLUE;
        } else if (color.equals("YELLOW")) {
            return Color.YELLOW;
        } else if (color.equals("WHITE")) {
            return Color.WHITE;
        } else if (color.equals("BLACK")) {
            return Color.BLACK;
        } else if (color.equals("GRAY")) {
            return Color.GRAY;
        } else if (color.equals("PINK")) {
            return Color.PINK;
        } else if (color.equals("ORANGE")) {
            return Color.ORANGE;
        } else if (color.equals("MAGENTA")) {
            return Color.MAGENTA;
        }
        return null;
    }
}
